VT-d: get rid of hardcode in iommu_flush_cache_entry
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 2 Dec 2009 08:48:36 +0000 (08:48 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 2 Dec 2009 08:48:36 +0000 (08:48 +0000)
Currently iommu_flush_cache_entry uses a fixed size 8 bytes to flush
cache. But it also needs to flush caches with different sizes,
e.g. struct root_entry is 16 bytes. This patch fixes the hardcode by
using a parameter "size" to flush caches with different sizes.

Signed-off-by: Weidong Han <weidong.han@intel.com>
xen/drivers/passthrough/vtd/intremap.c
xen/drivers/passthrough/vtd/iommu.c
xen/drivers/passthrough/vtd/vtd.h

index b6d1922bbe1d4bdaafeaf7c8d72b90d6e37aefb6..87c639d50159546c519c6e7fbbbcc8b25d93ad63 100644 (file)
@@ -155,7 +155,7 @@ static void free_remap_entry(struct iommu *iommu, int index)
                      iremap_entries, iremap_entry);
 
     memset(iremap_entry, 0, sizeof(struct iremap_entry));
-    iommu_flush_cache_entry(iremap_entry);
+    iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
 
     unmap_vtd_domain_page(iremap_entries);
@@ -329,7 +329,7 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu,
     }
 
     memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry));
-    iommu_flush_cache_entry(iremap_entry);
+    iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
     invalidate_sync(iommu);
 
@@ -635,7 +635,7 @@ static int msi_msg_to_remap_entry(
     remap_rte->data = 0;
 
     memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry));
-    iommu_flush_cache_entry(iremap_entry);
+    iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
     invalidate_sync(iommu);
 
index 3efcc89e21b6b46500c21d5defc4fa634e9d9354..4cd07090a8df90e8dd59b559deba2bb6555e5486 100644 (file)
@@ -117,7 +117,7 @@ struct iommu_flush *iommu_get_flush(struct iommu *iommu)
 
 static unsigned int clflush_size;
 static int iommus_incoherent;
-static void __iommu_flush_cache(void *addr, int size)
+static void __iommu_flush_cache(void *addr, unsigned int size)
 {
     int i;
 
@@ -128,9 +128,9 @@ static void __iommu_flush_cache(void *addr, int size)
         cacheline_flush((char *)addr + i);
 }
 
-void iommu_flush_cache_entry(void *addr)
+void iommu_flush_cache_entry(void *addr, unsigned int size)
 {
-    __iommu_flush_cache(addr, 8);
+    __iommu_flush_cache(addr, size);
 }
 
 void iommu_flush_cache_page(void *addr, unsigned long npages)
@@ -190,7 +190,7 @@ static u64 bus_to_context_maddr(struct iommu *iommu, u8 bus)
         }
         set_root_value(*root, maddr);
         set_root_present(*root);
-        iommu_flush_cache_entry(root);
+        iommu_flush_cache_entry(root, sizeof(struct root_entry));
     }
     maddr = (u64) get_context_addr(*root);
     unmap_vtd_domain_page(root_entries);
@@ -249,7 +249,7 @@ static u64 addr_to_dma_page_maddr(struct domain *domain, u64 addr, int alloc)
              */
             dma_set_pte_readable(*pte);
             dma_set_pte_writable(*pte);
-            iommu_flush_cache_entry(pte);
+            iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
         }
         else
         {
@@ -546,9 +546,9 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)
         return;
     }
 
-    dma_clear_pte(*pte); 
+    dma_clear_pte(*pte);
     spin_unlock(&hd->mapping_lock);
-    iommu_flush_cache_entry(pte);
+    iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
 
     /* No need pcidevs_lock here since do that on assign/deassign device*/
     for_each_drhd_unit ( drhd )
@@ -587,7 +587,7 @@ static void iommu_free_pagetable(u64 pt_maddr, int level)
             iommu_free_pagetable(dma_pte_addr(*pte), next_level);
 
         dma_clear_pte(*pte);
-        iommu_flush_cache_entry(pte);
+        iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
     }
 
     unmap_vtd_domain_page(pt_vaddr);
@@ -1178,7 +1178,7 @@ static int domain_context_mapping_one(
     context_set_address_width(*context, agaw);
     context_set_fault_enable(*context);
     context_set_present(*context);
-    iommu_flush_cache_entry(context);
+    iommu_flush_cache_entry(context, sizeof(struct context_entry));
     spin_unlock(&iommu->lock);
 
     /* Context entry was previously non-present (with domid 0). */
@@ -1309,7 +1309,7 @@ static int domain_context_unmap_one(
 
     context_clear_present(*context);
     context_clear_entry(*context);
-    iommu_flush_cache_entry(context);
+    iommu_flush_cache_entry(context, sizeof(struct context_entry));
 
     if ( iommu_flush_context_device(iommu, domain_iommu_domid(domain),
                                     (((u16)bus) << 8) | devfn,
@@ -1485,7 +1485,7 @@ static int intel_iommu_map_page(
     if ( iommu_snoop )
         dma_set_pte_snp(*pte);
 
-    iommu_flush_cache_entry(pte);
+    iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
     spin_unlock(&hd->mapping_lock);
     unmap_vtd_domain_page(page);
 
index b81e5b42d6cfbf1d60d0d70ad0a884150e2f6fed..e91ce67b21b95d7f9ceb72e3e1ca58a4a52d0689 100644 (file)
@@ -105,7 +105,7 @@ void free_pgtable_maddr(u64 maddr);
 void *map_vtd_domain_page(u64 maddr);
 void unmap_vtd_domain_page(void *va);
 
-void iommu_flush_cache_entry(void *addr);
+void iommu_flush_cache_entry(void *addr, unsigned int size);
 void iommu_flush_cache_page(void *addr, unsigned long npages);
 
 #endif // _VTD_H_